package com.example.demo.config;

import com.example.demo.interceptor.AdminInterceptor;
import com.example.demo.interceptor.UserInterceptor;
import com.example.demo.interceptor.VipUserInterceptor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.annotation.Resource;

@Configuration
@Slf4j
public class WebConfig implements WebMvcConfigurer {

    @Resource
    private UserInterceptor userInterceptor;


    @Resource
    private AdminInterceptor adminInterceptor;

    @Resource
    private VipUserInterceptor vipUserInterceptor;


    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        log.info("添加拦截器");

        // 配置管理员拦截器，假设所有管理员相关的接口都在/admins/路径下
        registry.addInterceptor(adminInterceptor)
                .addPathPatterns("/admins/**")
                .excludePathPatterns("/admins/login",
                        "/admins/outLogin"); // 仅对/admins/路径下的接口应用此拦截器

        // 配置vip用户拦截器，假设所有管理员相关的接口都在/vips/路径下
        registry.addInterceptor(vipUserInterceptor)
                .addPathPatterns("/vips/**");// 仅对/vips/路径下的接口应用此拦截器
        // 配置用户拦截器
        registry.addInterceptor(userInterceptor)
                .addPathPatterns("/**")
                .excludePathPatterns("/users/login",
                        "/users/outLogin",
                        "/users/register",
                        "/users/findPassWord",
                        "/files/**",
                        "/admins/**",
                        "/vips/**",
                        "/QRcodes/**",
                        "/emails/send/findCode",
                        "/QRcodes/createQRCode",
                        "/favicon.ico",
                        "/error",
                        "/*.html",
                        "/*.js",
                        "/*.css"// 管理员路径不应由用户拦截器处理
                ); // 这里可以排除不需要进行Token验证的路径
    }

}